package 反射2;
/*
@Date:2025/3/17
*/

import com.alibaba.druid.sql.visitor.functions.Char;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestBoss {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        //1.得到反射类对象
        //  Class<?> aClass = Class.forName("反射2.Boss");
        final Class<Boss> aClass = Boss.class;
        //2.创建类对象
        Object o1 = aClass.newInstance();
        //3.调用private中say方法
        Method say = aClass.getDeclaredMethod("Say", int.class, String.class, Char.class);
        //4.关闭访问权限
        say.setAccessible(true);
        //5.反射调用方法 invoke
        // Object invoke = say.invoke(o1, 100, "王五", '男');
        // System.out.println("invoke = " + invoke);
//访问公共的hi方法
        final Method hi = aClass.getDeclaredMethod("hi", String.class);
        final Object java编程 = hi.invoke(o1, "java编程");
        System.out.println("java编程 = " + java编程);
        final Method m1 = aClass.getDeclaredMethod("m1");
        final Object invoke = m1.invoke(o1);
        System.out.println("invoke = " + invoke);
        System.out.println("invoke.getClass() = " + invoke.getClass());

    }
}
